package com.system.appointment.controller;

import com.system.appointment.bean.Appointment;
import com.system.appointment.dto.AppointmentDTO;
import com.system.appointment.dto.CallingMachineDTO;
import com.system.appointment.dto.OutTradeNoDTO;
import com.system.appointment.dto.PatientQueryDTO;
import com.system.appointment.service.AppointmentService;
import com.system.appointment.vo.AppointmentListVO;
import com.system.appointment.vo.AppointmentPatientDetailVO;
import com.system.appointment.vo.CallingMachineVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @className: AppointmentController
 * @description: 预约单控制类
 * @author: Li Chuanwei
 * @date: 2023/11/26 20:46
 * @Company: Copyright [日期] by [作者或个人]
 **/

@RestController
@RequestMapping("/appointment")
public class AppointmentController {

    @Autowired
    private AppointmentService appointmentService;

    @PostMapping("/save")
    public boolean saveHandle(@RequestBody Appointment appointment){
        return appointmentService.saveAppointment(appointment);
    }

    @DeleteMapping("/del/{id}")
    public boolean deleteHandle(@PathVariable("id") int id){
        return appointmentService.removeAppointmentById(id);
    }

    @PutMapping("/update")
    public boolean updateHandle(@RequestBody Appointment appointment){
        return appointmentService.modifyAppointment(appointment);
    }

    @GetMapping("/get/{id}")
    public Appointment getHandle(@PathVariable("id") int id){
        return appointmentService.getAppointmentById(id);
    }

    @GetMapping("/get/list")
    public List<Appointment> listHandle(){
        return appointmentService.listAllAppointments();
    }

    /**
     * 提交预约单
     */
    @PostMapping("/submitAppointment")
    public Integer submitAppointment(@RequestBody AppointmentDTO appointmentDTO){
        return appointmentService.processAppointment(appointmentDTO);
    }

    @PostMapping("/cancelAppointment/{id}")
    public boolean cancelAppointment(@PathVariable("id") int id){
        return appointmentService.cancelAppointment(id);
    }

    @GetMapping("/getPatientDetail/{id}")
    public AppointmentPatientDetailVO getPatientDetail(@PathVariable("id") int id){
        return appointmentService.getPatientDetail(id);
    }

    @PostMapping("/getByPatientIdCardNumberOrAppointmentNumber")
    public CallingMachineVo getAppointmentByPatientIdCardNumber(@RequestBody CallingMachineDTO callingMachineDTO){
        return appointmentService.getAppointmentByPatientIdCardNumber(callingMachineDTO);
    }

    @PostMapping("/paySuccess")
    public Integer paySuccess(@RequestBody OutTradeNoDTO outTradeNoDTO){
        return appointmentService.paySuccess(outTradeNoDTO.getOut_trade_no());
    }

    @PostMapping("/getAppointmentList/list")
    public List<AppointmentListVO> getAppointmentList(@RequestBody PatientQueryDTO patientQueryDTO){
        return appointmentService.getAppointmentList(patientQueryDTO);
    }
}
